<template>
    <div class="select_tools">
        <div
                class="tool_item"
                v-for="tool in curTools"
                :key="tool.key"
                draggable="true"
                @dragstart="(e) => {
                  dragHandler(e, tool.key)
                }"
        >
            <img :src="tool.source" alt="">
            <p>{{tool.key}}</p>
        </div>
        <div
                @click="closeTools"
                class="tool_item">
            <img :src="close" alt="">
            <p>关闭</p>
        </div>
    </div>
</template>

<script>
  import {mapState} from 'vuex';
  import close from '../../assets/img/close.png';

  export default {
    name: "IndexTools",
    data() {
      return {
        close,
      }
    },
    computed: {
      ...mapState(['curTools'])
    },
    methods: {
      closeTools() {
        this.$store.commit('closeTools');
      },
      dragHandler(e, key) {
        e.dataTransfer.setData("key", key)
      }
    }
  }
</script>

<style scoped lang="scss">
    .select_tools {
        width: 100%;
        min-height: 40px;
        padding: 4px 20px;
        display: flex;
        justify-content: flex-start;
        align-items: center;
        position: relative;
        border-top: 1px solid #cbcccc;
        -webkit-box-shadow: inset 0 1px 0 0 #fff;
        -moz-box-shadow: inset 0 1px 0 0 #fff;
        box-shadow: inset 0 1px 0 0 #fff;
        background-color: #f5f5f5;
        background-image: linear-gradient(to bottom, #f5f5f5, #eee);
        border-bottom: 1px solid #aaaaaa;

        .tool_item {
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            width: 50px;
            font-size: 12px;

            img {
                -webkit-user-drag: none;
                width: 20px;
                height: 20px;
                margin-bottom: 4px;
            }
        }
    }

</style>
